<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const add = () => {
            const cache = {};
            return num => {
                if (num in cache) {
                    return `From cache! ${cache[num]}`;
                } else {
                    const result = num + 10;
                    cache[num] = result;
                    return `Calculated! ${result}`;
                }
            };
        };

        const addFunction = add();
        console.log(addFunction(10));
        console.log(addFunction(10));
        console.log(addFunction(5 * 2));
    </script>
</body>

</html>